package org.example.thread.testSync;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;

/**
 * @author liyishan
 * @date 2025/4/3
 * @description
 */
public class TestCompletableFuture {
    public static final ExecutorService PHOTO_SEARCH_THREAD_POOL = new ThreadPoolExecutor(5, 10, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue<>(200), new ThreadFactoryBuilder().setNameFormat("photo_search_%d").build(), new ThreadPoolExecutor.DiscardPolicy());

    public static void main(String[] args) {
        List<CompletableFuture<Void>> futures = new ArrayList<>();
        Map<String, List<String>> modelParamResultMap = new ConcurrentHashMap<>();
        List<String> list = new ArrayList<>();
        list.add("1");
        list.forEach(item -> {
            CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> buildParamInfo(item, modelParamResultMap), PHOTO_SEARCH_THREAD_POOL);
            futures.add(completableFuture);
        });
        try {
            CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
            System.out.println("end");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private static void buildParamInfo(String key, Map<String, List<String>> modelParamResultMap) {
        throw new RuntimeException("test");

    }
}
